package com.luoqiu.cinema.controller;

import com.luoqiu.cinema.common.BuyMovieParam;
import com.luoqiu.cinema.common.PageParam;
import com.luoqiu.cinema.common.PageResult;
import com.luoqiu.cinema.common.Result;
import com.luoqiu.cinema.eitityExtends.TicketEx;
import com.luoqiu.cinema.entity.Movie;
import com.luoqiu.cinema.entity.MoviePlace;
import com.luoqiu.cinema.service.TicketService;
import com.luoqiu.cinema.util.UserInfoUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
public class TicketController {

    @Resource
    private TicketService ticketService;

    /**
     * 获取所有的电影
     * @param pageParam
     * @return
     */
    @PostMapping(value = "/movie/all")
    public Result<PageResult<Movie>> allMovie(@RequestBody PageParam pageParam) {
        return ticketService.allMovies(pageParam);
    }

    /**
     * 通过电影选择电影院
     * @param pageParam
     * @return
     */
    @PostMapping(value = "/movie/place")
    public Result<PageResult<MoviePlace>> allPlace(@RequestBody PageParam pageParam) {
        return ticketService.allPlace(pageParam);
    }

    /**
     * 获取位置
     * @param movieId
     * @param placeId
     * @return
     */
    @GetMapping(value = "/movie/location")
    public Result<Map<String, List<String>>> getLocation(Integer movieId, Integer placeId) {
        return ticketService.getLocation(movieId, placeId);
    }

    /**
     * 买票
     * @param buyMovieParam
     * @return
     */
    @PostMapping(value = "/movie/buy")
    public Result<String> buyMovie(@RequestBody BuyMovieParam buyMovieParam) {
        return ticketService.buyMovie(buyMovieParam);
    }

    /**
     * 查询电影票
     * @param pageParam
     * @return
     */
    @PostMapping(value = "/ticket/qry")
    public Result<PageResult<TicketEx>> qry(@RequestBody PageParam pageParam){
        return ticketService.qry(pageParam);
    }


    /**
     * 退票
     * @param id
     * @return
     */
    @GetMapping(value = "/ticket/rollback")
    public Result<String> rollback(Integer id) {
        ticketService.rollback(id);
        return Result.success("OK");
    }

}
